var rooturl="http://127.0.0.1:8080/";
function logout()
	{
		
		 localStorage.removeItem('cuser');
		 window.location.href="ulogin.html";
	}
	layui.use('table', function() {
		var table = layui.table,
			form = layui.form;
		 
		form.on('submit(userSubmit)', function(data) {
			formSubmit(data);
			return false;
		});
	});
	data=localStorage.getItem("cuser");
	//data=JSON.stringify(data);
	data=JSON.parse(data);
 
	if(data!=null)
	{
		document.getElementById("name").innerHTML=data.ordinaryUserName;
			document.getElementById("uimg").src = rooturl+data.ordinaryUserImg;
	}
	else{
		localStorage.removeItem('cuser');
		window.location.href="login.html";
	}

layui.use('element', function(){
  var element = layui.element;
  
});
function confirm()
{
layer.confirm('同意报名协议？', {
  btn: ['同意','不同意'] //按钮
}, function(){
	 window.location.href="addinfo.html";  
  layer.msg('同意', {icon: 1});
}, function(){
  layer.msg('不同意', {
    time: 20000, //20s后自动关闭
     
  });
});
}
function getUserAndRoles() {
		//回显数据
		$.get(rooturl+"getUserAndRoles", {
			"id": data.id
		}, function(data) {
			if(data.msg == "ok") {
				$("#Id").val(data.user.id == null ? '' : data.user.id);
				$("#OrdinaryUserName").val(data.user.ordinaryUserName == null ? '' : data.user.ordinaryUserName);
				$("#OrdinaryUserEmail").val(data.user.ordinaryUserEmail == null ? '' : data.user.ordinaryUserEmail);
				$("#OrdinaryUserImg").val(data.files== null ? '' : data.files);
				$("#OrdinaryUserStatus").val(data.user.ordinaryUserStatus == null ? '' : data.user.ordinaryUserStatus);
				$("#IdNumber").val(data.user.idNumber == null ? '' : data.user.idNumber);
				$("#OrdinaryUserPassword").val(data.user.ordinaryUserPassword == null ? '' : data.user.ordinaryUserPassword);
				openUser("修改用户");
			} else {
				//弹出错误提示
				layer.alert(data.msg, function() {
					layer.closeAll();
					
				});
			}
		});
	}
	function formSubmit() {
		$.ajax({
			type: "POST",
			data: $("#userForm").serialize(),
			url: rooturl+"updataUserInfo",
			success: function(data) {
				if( data.data== "ok") {
					layer.alert("操作成功,请重新登录！", function() {
						window.location.href="ulogin.html";
					});
				} else {
					
				  layer.alert(data);
				}
			},
			error: function() {
				layer.alert("操作请求错误，请您稍后再试", function() {
					layer.closeAll();
				});
			}
		});
	}
	
	function upfile()
	{
		layer.open({
			type: 1,
			title: "上传图片",
			fixed: false,
			resize: false,
			shadeClose: true,
			area: ['200px'],
			content: $('#upfile')
		});
	}
	
	function openUser(title) {
		layer.open({
			type: 1,
			title: title,
			fixed: false,
			resize: false,
			shadeClose: true,
			area: ['550px'],
			content: $('#setUser')
		});
	}